package com.ghck.server.service.impl;
import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ghck.server.dao.PatientEventExtMapper;
import com.ghck.server.model.PatientEventExt;
import com.ghck.server.model.query.PatientEventExtQuery;
import com.ghck.server.service.PatientEventExtService;

/**
 * 用户健康数据扩展表  <br>
 * t_patient_event_ext <br>
 * v1.0 2016-05-01
 */
 @Service
 @Transactional
 public class PatientEventExtServiceImpl implements PatientEventExtService {
	
	private static final Logger logger = LoggerFactory.getLogger(PatientEventExtServiceImpl.class);
	
	@Autowired
	private PatientEventExtMapper patientEventExtMapper;
	
	/**
 	*根据ID删除 用户健康数据扩展表
 	*/
 	@Override
 	public Integer deletePatientEventExtById(Integer id){
 		return patientEventExtMapper.deleteById(id);
 	}
 	
 	/**
 	*新增 用户健康数据扩展表
 	*/
 	@Override
 	@Transactional
 	public Integer batchInsertPatientEventExt(List<? extends PatientEventExt> patientEventExts){
		Integer count = patientEventExtMapper.batchInsert(patientEventExts);
		return count;
 	}
 	/**
 	*新增 用户健康数据扩展表
 	*/
 	@Override
 	@Transactional
 	public Integer insertPatientEventExt(PatientEventExt domain){
		Integer id = patientEventExtMapper.insert(domain);
		return id;
 	}

 	/**
 	*更新 用户健康数据扩展表
 	*/
 	@Override
 	@Transactional
 	public Integer updatePatientEventExt(PatientEventExt domain){
		Integer count = patientEventExtMapper.update(domain);
		return count;
 	}
 	
 	/**
 	*根据ID查询 用户健康数据扩展表
 	*/
 	public PatientEventExt findPatientEventExtById(Integer id){
 		PatientEventExt result = patientEventExtMapper.findById(id);
 		if(result!=null){
 			result.dealWith();
 		}
 		return result;
 	}

	/**
 	*通过query 查询 用户健康数据扩展表
 	*/
	public List<PatientEventExt> findPatientEventExtByQuery(PatientEventExtQuery query){
		query.dealWith();
		List<PatientEventExt> result = patientEventExtMapper.findByQuery(query);
		if(CollectionUtils.isNotEmpty(result)) {
			for (PatientEventExt patientEventExt : result) {
				patientEventExt.dealWith();
			}
		}
		return result;
	}	
	
	/**
 	*通过query count总条数
 	*/
 	public Integer countPatientEventExtByQuery(PatientEventExtQuery query){
 		query.dealWith();
 		Integer result = patientEventExtMapper.countByQuery(query);
 		return result;
 	}
 	
 	/**
 	* 通过ids查询
 	*/
 	public List<PatientEventExt> findPatientEventExtByIds(List<Integer> ids){
 		List<PatientEventExt> result = patientEventExtMapper.findByIds(ids);
		if(CollectionUtils.isNotEmpty(result)) {
			for (PatientEventExt patientEventExt : result) {
				patientEventExt.dealWith();
			}
		}
		return result;
 	}
 	
}	